<?php
class ModuleShopsProductRelated extends Controller {
	public function productRelated($shop_id, $max_record, $zone_id = '') {
		//-------------------------------------------------------------------------//
		// get Shop Id
		//-------------------------------------------------------------------------//
		$this->load->model('upload/shop');
		$this->load->model('catalog/product');
		$this->load->model('shops/select');
		$this->load->model('catalog/review');
		$this->load->model('tool/seo_url');
		$this->language->load('module/shops');
		$this->load->helper('image');

      	$this->data['heading_title'] = $this->language->get('heading_title');
		$this->data['products'] = array();
		$max_record =  $this->config->get('config_max_record_shop');
		$results = $this->model_catalog_product->getLastProductsByShopId($shop_id,$max_record, $zone_id = "");
		$shopInfo = $this->model_shops_select->getShopNameByShopId($shop_id);

		$shop_name = "";
		if(empty($shopInfo) == false){
			$shop_name = $shopInfo[0]['shop_name'];
		}

		if(empty($results) == false){
		foreach ($results as $result)
		{
			if ($result['image']) {
				$image = $result['image'];
			} else {
				$image = 'no_image.jpg';
			}

			$rating = $this->model_catalog_review->getAverageRating($result['product_id']);
			$special = $this->model_catalog_product->getProductSpecial($result['product_id']);

			if ($special) {
				$special = $this->currency->format($this->tax->calculate($special, $result['tax_class_id'], $this->config->get('config_tax')));
			} else {
				$special = FALSE;
			}

			$this->data['products'][] = array(
				'name'    => $this->model_catalog_product->wrapString($result['name']),
				'price'   => $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'))),
				'special' => $special,
				'image'   => image_resize($image, 38, 38),
				'href'    => $this->model_tool_seo_url->rewrite($this->url->http('shops/shop_customer&product_id=' . $result['product_id']))
			);			
		}}

		if (!$this->config->get('config_customer_price')) {
			$this->data['display_price'] = TRUE;
		} elseif ($this->customer->isLogged()) {
			$this->data['display_price'] = TRUE;
		} else {
			$this->data['display_price'] = FALSE;
		}
		$this->data['shop_name'] = $this->url->http('shops/shop&shop='.$shop_name);
		$this->data['count'] = count($this->data['products']);

		$this->template = $this->config->get('config_template') . 'module/product_related.phtml';
		$productRelated = $this->fetch($this->template);
		return $productRelated;
	}
}
?>